package edu.uwg.LewisWilliams.android.assignment1;

import edu.uwg.LewisWilliams.android.assignment1.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
/**
 * GetUserNameActivity takes in a variety of user inputs and affects the information
 * displayed on subsequent activity pages.
 * 
 * @author Charles Williams
 * @version 2011.9.9
 */
public class GetUserNameActivity extends Activity {
	private EditText editText;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.get_user_name);
        editText = (EditText) this.findViewById(R.id.nameEntered);
        
        //Finds and retrieves the simple welcome button
        Button simpleWelcomeButton = (Button) this.findViewById(R.id.simpleWelcomeButton);
        
        //Adds the listener to the simple welcome button and defines it's behavior
        simpleWelcomeButton.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		//Retrieves the name the user entered
        		Editable userName = editText.getText();
        		Intent intent = new Intent(GetUserNameActivity.this, HelloActivity.class);
        		//Passes the name in the text field
        		intent.putExtra("userName", userName.toString());
        		//Starts the Hello Activity
        		GetUserNameActivity.this.startActivity(intent);
        	}
        	});
        
        //Finds and retrieves the extended welcome button
        Button extendedWelcomeButton = (Button) this.findViewById(R.id.extendedWelcomeButton);
        //Finds and retrieves the happy check box 
        final CheckBox happyCheckBox = (CheckBox) this.findViewById(R.id.happyCheckBox);
        
        //Adds the listener to the extended welcome button and defines it's behavior
        extendedWelcomeButton.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		Intent intent = new Intent(GetUserNameActivity.this, ExtendedWelcomeActivity.class);
        		//Passes the status of the checkbox
        		intent.putExtra("isChecked", happyCheckBox.isChecked());
        		//Starts the Extended Welocme activity
        		GetUserNameActivity.this.startActivity(intent);
        	}
        	});
    }
        
        //**Code from previous version that only had one button.**
//        simpleWelcomeButton.setOnClickListener(this);
//    }
//    
//	public void onClick(View v) {
//		Editable userName = editText.getText();
//		Intent intent = new Intent(this, HelloActivity.class);
//		intent.putExtra("userName", userName.toString());
//		
//		this.startActivity(intent);
//	}
    	
}
